/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package admintool.imp03_data;

import admintool.AdminToolView;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author Administrator
 */
public class IMP03_Gender {

    private class Genders{

        private int genderID = 0;
        private String genderName = "";
        
        public Genders(int genderID, String genderName) {
            this.genderID = genderID;
            this.genderName = genderName;
        }

        public int getGenderID() {
            return genderID;
        }

        public String getGenderName() {
            return genderName;
        }
    }
    
    private static ArrayList<IMP03_Gender> genders = new ArrayList<IMP03_Gender>();
    
    /**
     * 
     * @return
     */
    public static IMP03_Gender getEmptyGenderObject(){
        return new IMP03_Gender(-1, AdminToolView.EMPTY);
    }
    
    /**
     * 
     * @param reload
     * @return
     */
    public static ArrayList<IMP03_Gender> getAllAvailableGendersFromDB(boolean reload){
        PreparedStatement ps = null;
        ResultSet rs = null;

        try {
            if(reload == true || genders.isEmpty()){
                genders.clear();
                ps = AdminToolView.getDBConnection().prepareStatement("SELECT * FROM gender");
                rs = ps.executeQuery();
                while(rs.next()){
                    genders.add(new IMP03_Gender(rs.getInt(1), rs.getString(2)));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if(rs != null){
                    rs.close();
                }
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e) {
            }
        }
        return genders;
    }
    
    private Genders gender = null;
    
    /**
     * 
     * @param genderID
     * @param genderName
     */
    public IMP03_Gender(int genderID, String genderName) {
        this.gender = new Genders(genderID, genderName);
    }
    
    /**
     * 
     * @return
     */
    public int getGenderID(){
        return gender.getGenderID();
    }

    /**
     * 
     * @return
     */
    public String getGenderName(){
        return gender.getGenderName();
    }

    @Override
    public String toString() {
        return gender.getGenderName();
    }
}
